package com.crlclr.ui.itemrenders
{
	import caurina.transitions.Tweener;
	
	import com.crl.ui.controls.listClass.ListItemRenderer;
	import com.crlclr.data.qzone.AlbumVO;
	import com.crlclr.managers.QTextFormat;
	import com.crlclr.managers.SkinManager;
	
	import flash.display.Bitmap;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class AlbumItemRender extends ListItemRenderer
	{
		private static const  LINKAGE:String = "SinglePage";
		
		private var vo:AlbumVO;
		private var _skin:*;
		
		public var defaultX:int;
		public var index:int;
		
		private var textField:TextField;
		public function AlbumItemRender()
		{
			super();
			
			var skinClass:*= SkinManager.getInstance().getClass(LINKAGE);
			_skin= new skinClass();
			
			_skin.addEventListener(MouseEvent.ROLL_OVER,rollHandler);
			_skin.addEventListener(MouseEvent.ROLL_OUT,rollHandler);
			
			
			textField=new TextField();
			textField.background=true;
			textField.backgroundColor=0xff99cc
				
			//textField.border=true;
			//textField.borderColor=0xffffff;
			textField.mouseEnabled=false;
			textField.width=_skin.width;
			textField.autoSize=TextFieldAutoSize.CENTER;
			
			var dtf:TextFormat=QTextFormat.whiteTextFormat;
			textField.defaultTextFormat=dtf;
			
			textField.x=_skin.x;
			textField.y=(_skin.height>>1)-30;
			
			this.addChild(_skin);
			this.addChild(textField);
		}
		
		
		public function rollHandler(event:MouseEvent):void {
			var type:String=event.type;
			var target:Sprite=event.currentTarget as Sprite;
			switch(type)
			{
				case MouseEvent.ROLL_OVER :
					Tweener.addTween(target,{scaleX:1.1,scaleY:1.1,time:.2})
					break;
				case MouseEvent.ROLL_OUT :
					Tweener.addTween(target, { scaleX:1.0, scaleY:1.0, time:.2 } );
					break;
			}
		}
		
		
		override public function set data(value:*) : void{
			super.data=value;
			this.vo=value as AlbumVO;
			if(vo){
				this.textField.text=" 相册名称:"+vo.name;
				//this.textField.y=_skin.height-this.textField.height;
			}
		}
		
		public function set bitmap(value:Bitmap):void{
			
			var bitmapContainer:Sprite=_skin.img.getChildByName("bitmapContainer");
			if(bitmapContainer ==null){
				bitmapContainer=new Sprite();
				bitmapContainer.name="bitmapContainer";
				_skin.img.addChild(bitmapContainer);
			}
			
			var g:Graphics=bitmapContainer.graphics;
			g.beginBitmapFill(value.bitmapData,null);
			g.drawRect(0,0,_skin.width,_skin.height);
			g.endFill();
		}
		
	}
}